<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Redis;

class TagController extends Controller
{
    public function create()
    {
        return view('tag.create');
    }

    public function product()
    {
        $attrs = [
            [
                'attr_name' => 'color',
                'attr_value' => [
                    'A', 'B', 'C'
                ]
            ],
            [
                'attr_name' => 'size',
                'attr_value' => [
                    'D', 'E', 'F'
                ]
            ],
            [
                'attr_name' => 'type',
                'attr_value' => [
                    'G', 'H'
                ]
            ]
        ];
        $skus = [
            [
                'id' => 1,
                'sku' => 'ADG',
                'price' => mt_rand(10, 99)
            ],
            [
                'id' => 2,
                'sku' => 'ADH',
                'price' => mt_rand(10, 99)
            ],
            [
                'id' => 3,
                'sku' => 'AEG',
                'price' => mt_rand(10, 99)
            ],
            [
                'id' => 4,
                'sku' => 'AEH',
                'price' => mt_rand(10, 99)
            ],
            [
                'id' => 5,
                'sku' => 'AFG',
                'price' => mt_rand(10, 99)
            ],
            [
                'id' => 6,
                'sku' => 'AFH',
                'price' => mt_rand(10, 99)
            ],
            [
                'id' => 7,
                'sku' => 'BDG',
                'price' => mt_rand(10, 99)
            ],
            [
                'id' => 8,
                'sku' => 'BDH',
                'price' => mt_rand(10, 99)
            ],
            [
                'id' => 9,
                'sku' => 'BEG',
                'price' => mt_rand(10, 99)
            ],
            [
                'id' => 10,
                'sku' => 'BEH',
                'price' => mt_rand(10, 99)
            ],
            [
                'id' => 11,
                'sku' => 'BFG',
                'price' => mt_rand(10, 99)
            ],
            [
                'id' => 12,
                'sku' => 'BFH',
                'price' => mt_rand(10, 99)
            ],
            [
                'id' => 13,
                'sku' => 'CDG',
                'price' => mt_rand(10, 99)
            ],
            [
                'id' => 14,
                'sku' => 'CDH',
                'price' => mt_rand(10, 99)
            ],
            [
                'id' => 15,
                'sku' => 'CEG',
                'price' => mt_rand(10, 99)
            ],
            [
                'id' => 16,
                'sku' => 'CEH',
                'price' => mt_rand(10, 99)
            ],
            [
                'id' => 17,
                'sku' => 'CFG',
                'price' => mt_rand(10, 99)
            ],
            [
                'id' => 18,
                'sku' => 'CFH',
                'price' => mt_rand(10, 99)
            ],
        ];
        $json_skus = json_encode($skus);
        return view('product.product', compact(['attrs', 'json_skus']));
    }

    public function redis()
    {
        Redis::del('name');
    }

    public function ipn(Request $request)
    {
        $data = $request->all();
        $ip = $request->ip();
        Log::info($data);
        Log::info($ip);
        header("HTTP/1.1 200 OK");
    }
}
